local skel = fk.CreateSkill {
  name = "emo__kuangqi",
}

Fk:loadTranslationTable{
  ["emo__kuangqi"] = "狂奇",
  [":emo__kuangqi"] = "本轮使用锦囊牌数与你相等的角色使用【杀】时，你可增加一个额外目标；装备区牌数与你相等的角色使用【闪】时，你可以令其视为对当前回合者使用【决斗】。",

  ["#emo__kuangqi-extra"] = "狂奇：你可以为 %dest 使用的 %arg 增加一个目标",
  ["#emo__kuangqi-duel"] = "狂奇：你可以令 %src 视为对 %dest 使用【决斗】",
}

skel:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    if data.card.trueName == "slash" then
      if #data:getExtraTargets() > 0 then
        if target == player then return true end
        return #player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
          return e.data.from == player and e.data.card.type == Card.TypeTrick
        end, Player.HistoryRound)
        == #player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
          return e.data.from == target and e.data.card.type == Card.TypeTrick
        end, Player.HistoryRound)
      end
    elseif data.card.trueName == "jink" then
      local current = player.room:getCurrent()
      return target:isAlive() and #target:getCardIds("e") == #player:getCardIds("e")
      and current and current ~= target and target:canUseTo(Fk:cloneCard("duel"), current)
    end
  end,
  on_cost = function (self, event, target, player, data)
    if data.card.trueName == "jink" then
      local current = player.room:getCurrent()
      if player.room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#emo__kuangqi-duel:"..target.id..":"..current.id }) then
        event:setCostData(self, {  tos = {target} })
        return true
      end
    else
      local tos = player.room:askToChoosePlayers(player, {
        min_num = 1, max_num = 1, targets = data:getExtraTargets(), skill_name = skel.name,
        prompt = "#emo__kuangqi-extra::" .. target.id .. ":" .. data.card:toLogString()
      })
      if #tos > 0 then
        event:setCostData(self, {tos = tos})
        return true
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if data.card.trueName == "jink" then
      room:useVirtualCard("duel", nil, target, room:getCurrent(), skel.name)
    else
      local to = event:getCostData(self).tos[1]
      data:addTarget(to)
    end
  end,
})

return skel
